/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package muticastclient;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import sun.rmi.runtime.Log;

/**
 *
 * @author Minh
 */


    /**
     * @param args the command line arguments
     */
    class MultiCastThread implements Runnable
    {
        MulticastSocket s;
        DatagramPacket pack;
        String st="Hello";
        public MultiCastThread()
        {
            try
            {
                s = new MulticastSocket(1234);
                s.joinGroup(InetAddress.getByName("225.4.5.6"));
            }
            catch(Exception e)
            {

            }
        }
        @Override
        public void run()
        {
            try
            {
                pack = new DatagramPacket(st.getBytes(),st.getBytes().length, InetAddress.getByName("225.4.5.6"), 1234);

                s.send(pack);
            }
            catch(Exception e)
            {

            }
        }
    }
public class MuticastClient {
    public static void main(String[] args) {
        // TODO code application logic here
        Runnable runnable = new MultiCastThread();
        System.out.println("Tao thread 1: ");
        Thread t1 = new Thread(runnable);
        System.out.println("Tao thread 2: ");
// Create the thread supplying it with the runnable object 
        Thread t2 = new Thread(runnable);
        System.out.println("chay 2 thread");
        t1.start(); 
        t2.start();
        
    }
}
